/**
 * @name: menu
 * @Description:
 * @Author: 方琦
 * @Date: 2022/8/11 20:05
 **/
import {makeAutoObservable} from 'mobx';

class MenuStore {
    constructor() {
        //自动
        makeAutoObservable(this);
    }

    //控制windows按钮菜单的显示与隐藏
    isDisplayStartMenu = false;

    //桌面的菜单
    // menuList = JSON.parse(sessionStorage.getItem("userInfo")).data[2].permission_information || []

    //底部右侧的菜单
    rightMenu = [
        {
            id: 30,
            title: '系统设置',
            icon: 'icon-shezhi',
            bg: '#33BD85',
            width: '230px',
            class_type: 3,
        },
        {
            id: 31,
            title: '个人资料',
            icon: 'icon-gerenfill',
            bg: '#00B6DE',
            width: '110px',
            class_type: 3,
        },
        {
            id: 32,
            title: '自定义字段',
            icon: 'icon-caidan',
            bg: '#FF7659',
            width: '110px',
            class_type: 3,
        },
        {
            id: 33,
            title: '自定义选项值',
            icon: 'icon-xuanxiang',
            bg: '#F26175',
            width: '110px',
            class_type: 3,
        },
        {
            id: 34,
            title: '省/市地区设置',
            icon: 'icon-dizhi',
            bg: '#5CA7DF',
            width: '110px',
            class_type: 3,
        },
        {
            id: 35,
            title: '计算器',
            icon: 'icon-jisuanqi',
            bg: '#D8BF8A',
            width: '110px',
            class_type: 3,
        },
        {
            id: 36,
            title: '快递查询',
            icon: 'icon-wuliukuaidi',
            bg: '#CF7B7B',
            width: '230px',
            class_type: 3,
        },
        {
            id: 37,
            title: '帮助中心',
            icon: 'icon-bangzhu',
            bg: '#D9C597',
            width: '110px',
            class_type: 3,
        }
    ];

    //正在展示的菜单
    displayMenu = [];

    //windows按钮开始菜单的显示
    showStartMenu(value = false) {
        if (value) {
            this.isDisplayStartMenu = value;
        } else {
            this.isDisplayStartMenu = !this.isDisplayStartMenu;
        }
    }

    //添加正在桌面展示的菜单
    addDisplayMenu(item) {
        this.isDisplayStartMenu = false;
        if (this.displayMenu.length < 10) {
            let i = 0;
            for (i; i < this.displayMenu.length; i++) {
                if (item.id === this.displayMenu[i].id) {
                    return;
                }
            }
            if (i === this.displayMenu.length) {
                this.displayMenu.push(item);
            }
        }
    }

    //删除正在桌面展示的菜单
    delDisplayMenu(id) {
        this.isDisplayStartMenu = false;
        this.displayMenu.forEach((item, index) => {
            if (item.id === id) {
                this.displayMenu.splice(index, 1);
            } else {
                return false;
            }
        });
    }

    //控制已展示在桌面的菜单的display值
    isDisPlayMenuItem(id, flag) {
        this.displayMenu.forEach((item) => {
            if (item.id === id) {
                item.isDis = flag;
            }
        })
    }

    //改变面包屑的激活样式
    isActiveMenuItem(id) {
        this.displayMenu.forEach((item) => {
            if (item.id === id) item.isActive = true;
            else item.isActive = false;
        });
    }
}

export default MenuStore;
